package com.yami.shop.api.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.UserBlock;
import com.yami.shop.bean.vo.UserVO;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.UserBlockService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/p/block")
@AllArgsConstructor
@Tag(name = "拉黑")
public class UserBlockController {

    private final UserBlockService userBlockService;

    @GetMapping("/page")
    @Operation(summary =  "举报标题列表", description = "举报标题列表")
    public ServerResponseEntity<IPage<UserVO>> page(PageParam<UserVO> page){
        String userId = SecurityUtils.getUser().getUserId();
        IPage<UserVO> iPage = userBlockService.page(page, userId);
        return ServerResponseEntity.success(iPage);
    }
    
    @GetMapping("/isBlock")
    @Operation(summary =  "举报标题列表", description = "举报标题列表")
    public ServerResponseEntity<Map<String, Boolean>> getByUserId(@RequestParam String blockUserId){
        String userId = SecurityUtils.getUser().getUserId();
        Map<String, Boolean> isBlock = userBlockService.isBlock(userId, blockUserId);
        return ServerResponseEntity.success(isBlock);
    }
    
    @PostMapping("/addOrDel")
    @Operation(summary =  "举报标题列表", description = "举报标题列表")
    public ServerResponseEntity addOrDel(@RequestBody @Valid UserBlock userBlock){
        String userId = SecurityUtils.getUser().getUserId();
        userBlockService.addOrDel(userId, userBlock);
        return ServerResponseEntity.success();
    }
    
    
    
    
}
